How to Create Custom Parameters

To create custom report parameters you need the Development package , Visual Studio 2015 and SQL Server Data Tools for Visual Studio 2015 installed.

When a new report is added to the Site Manager ( Tools > Manage Reports > Add button ), both .rdlc and .rpdsc files are required by the system. The information from the report description files (.rpdsc) and the content of the report from .rdlc file are saved into REPORTS, REPORTCONTEXT and REPORTENUM tables from database.

At display time, report parameters and datasources are read from the report using GetParameters() and GetDataSourceNames() methods from Microsoft.Reporting namespace. If the report has a stored procedure defined in the .rpdsc file then those parameters are also added to the list.

For in-depth details about how LS One reports are displayed check the ReportViewer plugin from SM folder and specifically the ReportViewerView control.

The final list of report parameters is used to generate the needed UI for filtering/searching data to be displayed in the report.

For in-dept details about how report filtering/searching UI is created check the ReportParameterControl control from ReportViewer plugin

 

To create a custom parameter, you will modify ReportParameterControl class and the report that needs this custom parameter.

Example: Custom text (string) parameter

  1. Open the Solution.sln and navigate to the ReportViewer plugin in the SM folder.

    ReportViewer plugin in Visual Studio

  2. Open the report you want to modify in Designer Mode and add your custom parameter.

    Add parameter to report

  3. Open ReportsParameterControl class from ReportViewer.Controls namespace
  4. Navigate to SetParameterSet internal method
  5. In the first switch add a new case for the new parameter - here the default value, database type, display order and display label are set. The string in the case clause (RECEIPTID) must match the name of the parameter as it was defined in the report, in uppercase.
    
    case "@RECEIPTID":
    	parameter.Value = "";
    	parameter.DataType = SqlDbType.NVarChar;
    	
    	
    	pair = AddToPair(parameter, true, "@RECEIPT");
    	pair.LabelText = Properties.Resources.Receipt + ":";
    	pair.Priority = 50;
    
    break;
    						
  6. In the second switch the control associated with the new parameter is created. Here you also need to define any get-set logic for the parameter value, including handling for any events on the parameter control. Here the string in the case clause (RECEIPT) must match the name of the parameter pair passed to the AddToPair method in the previous step.
    
    case "@RECEIPT":
    	selector = new TextBox();
    	selector.Size = new Size(150, 20);
    	((TextBox)selector).TextChanged += new EventHandler(ReceiptId_TextChanged);
    break;

    
    private void ReceiptId_TextChanged(object sender, EventArgs e)
    {
    	ParameterPair pair = (ParameterPair)((WeakReference)((TextBox)sender).Tag).Target;
    	
    	pair.Primary.Value = ((TextBox)sender).Text.Trim();
    }
  7. Build the solution, start SiteManager and load the modified report.
  8. You should see the custom parameter in the search/filtering area and in the report.

    Report with custom parameter